package cn.net.zidian.mvvm.activity;

import android.view.LayoutInflater;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;

import cn.net.zidian.bean.HistoryBean;
import cn.net.zidian.databinding.ActivityTodayBinding;
import cn.net.zidian.mvvm.adapter.TodayAdapter;
import cn.net.zidian.mvvm.vm.TodayVM;
import cn.net.zidian.util.HistoryData;

public class TodayActivity extends BaseActivity<TodayVM> {

    private ActivityTodayBinding viewBinding;

    @Override
    protected TodayVM viewModel() {
        return new TodayVM();
    }

    private TodayAdapter adapter = new TodayAdapter();

    @Override
    protected void initView() {
        initObserver();
        viewBinding = ActivityTodayBinding.inflate(LayoutInflater.from(this));
        setContentView(viewBinding.getRoot());
        viewBinding.titleBar.getLeftView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        viewBinding.rvList.setLayoutManager(new LinearLayoutManager(this));
        viewBinding.rvList.setAdapter(adapter);
        HistoryData.list.add(new HistoryBean("历史上的今天", "历史上的今天"));
        vm.getList();
    }

    public void initObserver() {
        vm.eventList.observe(this, list -> adapter.setNewData(list));
    }

}
